package net.reea.example.multiselect;

import net.reea.utils.LogService;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.example.smallandroidcodetester.R;

public class MultiSelectionActivity extends SherlockFragmentActivity {

	private Fragment currentFragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTheme(com.actionbarsherlock.R.style.Theme_Sherlock);
		setContentView(R.layout.library_activity);
		navigateTo(MultiSelectionFragment.class, false, null);
	}

	public void navigateTo(Class<?> fragmentClass, boolean addToBackstack, Bundle bundle) {
		LogService.log("", "navigating to [" + fragmentClass.getSimpleName() + "]");
		currentFragment = getSupportFragmentManager().findFragmentById(R.id.FrameLayout);
		if (!fragmentClass.isInstance(currentFragment)) {
			try {
				currentFragment = (Fragment) fragmentClass.newInstance();
				if (bundle != null) {
					currentFragment.setArguments(bundle);
				}
				FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
				if (addToBackstack) {
					transaction.addToBackStack(fragmentClass.getName());
				}
				transaction.replace(R.id.FrameLayout, currentFragment);
				transaction.commit();
			} catch (InstantiationException e) {
				// do nothing here
			} catch (IllegalAccessException e) {
				// do nothing here
			}
		}
	}

}
